#!/usr/bin/env python
#coding=utf-8;


import redis
import pymysql
import json
import sys

def process_item():
    # 创建redis数据库连接
    rediscli = redis.Redis(host='127.0.0.1',port=6379,db=0)

    # 创建mysql数据库连接
    mysqlcli = pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='liudh',db='itjuzi',charset='utf8')

    offset = 0
    while True:
        source, data = rediscli.blpop("itjuzi:items")
        data = data.decode('utf-8')
        item = json.loads(data)

        cursor = mysqlcli.cursor()
        cursor.execute("insert into company_basic_info_table(id,company_name,slogan,company_weibo,home_page,tags,company_intro,company_full_name,found_time,company_size,company_status) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",[int(item['info_id']),item['company_name'],item['slogan'],item['company_weibo'],item['home_page'],item['tags'],item['company_intro'],item['company_full_name'],item['found_time'],item['company_size'],item['company_status']])
        mysqlcli.commit()
        cursor.close()
        offset += 1
        print (offset)


if __name__ == "__main__":
    process_item()